package com.xiashitech.agent.proxy.hutool;

import com.xiashitech.agent.cache.classloader.ClassLoaderCache;
import com.xiashitech.agent.config.StartConfig;

import java.io.File;

public class FileUtil {

    private static String className = "cn.hutool.core.io.FileUtil";

    public static boolean exist(String path) {
        try {
            Class fileUtilClass = ClassLoaderCache.getLaunchClassLoader().loadClass(className);
            return (boolean)fileUtilClass.getMethod("exist", String.class).invoke(null,path);
        } catch (Throwable e) {
            StartConfig.throwableStackPrinter(e);
        }
        return false;
    }
    public static void appendUtf8String(String log, File f) {
        try {
            Class fileUtilClass = ClassLoaderCache.getLaunchClassLoader().loadClass(className);
            fileUtilClass.getMethod("appendUtf8String", String.class, File.class).invoke(null,StrUtil.format("[{}] {} \n", DateUtil.now(), log), f);
        } catch (Throwable e) {
            StartConfig.throwableStackPrinter(e);
        }
    }
}
